<template>
  <div class="container">
    <div class="closeBtn">
      <span class="iconfont iconicon-test"></span>
    </div>
    <div class="logo">
      <span class="iconfont iconnew"></span>
    </div>
    <div class="inputName">
      <authInput
        type="text"
        placeholder="请输入手机号"
        rules="^\d{3,16}$"
        err_message="请输入正确的手机号码"
        @input="setUserName"
      ></authInput>
    </div>
    <div class="inputPwd">
      <authInput
        type="password"
        placeholder="请输入密码"
        rules="^\d{3,16}$"
        err_message="请输入正确的密码"
        @input="setPassword"
      ></authInput>
    </div>
    <div class="btn">
      <authBtn text="登录" @send="sendLogin"></authBtn>
    </div>
    <div class="register">
        还没账号?<router-link to="/register">点击注册</router-link>
    </div>
  </div>
</template>

<script>
import authInput from "../components/authInput";
import authBtn from "../components/authBtn";
export default {
  components: {
    authInput: authInput,
    authBtn: authBtn
  },
  data() {
    return {
      username: "",
      password: ""
    };
  },
  methods: {
    setUserName(name) {
      this.username = name;
      // console.log("shoudao");
      // console.log(this.username)
    },
    setPassword(password) {
      this.password = password;
    },
    sendLogin() {
      // console.log('按钮被点击了')
      // console.log(`${this.username}和${this.password}`)
      this.$axios({
        url: "/login",
        method: "post",
        data: {
          username: this.username,
          password: this.password
        }
      }).then(res => {
        // 登陆成功后的逻辑
        // 先保存数据
        localStorage.setItem('token',res.data.data.token);
        localStorage.setItem('user_id',res.data.data.user.id);
        // 弹出提示
        if(!res.data.statusCode){
            this.$toast.success(res.data.message)
          }
          // 设置一定的时间，然后跳转到个人信息页面
          setTimeout(()=>{
            this.$router.push({
              name:"homePage"
            })
          },1000)
      });
    }
  }
};
</script>

<style lang="less" scoped>
.container {
  padding: 0 5.556vw;
}
.closeBtn {
  padding-top: 20px;
  .iconfont {
    font-size: 7.5vw;
  }
}
.logo {
  display: flex;
  justify-content: center;
  .iconfont {
    font-size: 35vw;
    color: #d81e06;
  }
}
.btn {
  margin-top: 20.556vw;
}
.register{
    text-align: center;
    margin-top: 6.667vw;
}
</style>